/*
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
 * MA  02110-1301, USA.
 *
 * http://www.gnu.org/copyleft/gpl.html
 */
package com.aionemu.gameserver.model.gameobjects.instance;

import com.aionemu.gameserver.ai.AIClasss;
import com.aionemu.gameserver.dataholders.DataManager;
import com.aionemu.gameserver.model.Race;
import com.aionemu.gameserver.model.TribeClass;
import com.aionemu.gameserver.model.gameobjects.Creature;
import com.aionemu.gameserver.model.gameobjects.Npc;
import com.aionemu.gameserver.model.gameobjects.Relations;
import com.aionemu.gameserver.model.gameobjects.knownList.AgressivNPCKnownList;
import com.aionemu.gameserver.model.gameobjects.player.Player;
import com.aionemu.gameserver.model.templates.spawn.SpawnTemplate;

/**
 * @author Mr. Poke
 *
 */
public class Guard extends Npc
{

	/**
	 * @param objId
	 * @param spawn
	 */
	public Guard(int objId, SpawnTemplate spawn)
	{
		super(objId, spawn);
		setKnownlist(new AgressivNPCKnownList(this));
	}

	/* (non-Javadoc)
	 * @see com.aionemu.gameserver.model.gameobjects.Creature#isAggroFrom(com.aionemu.gameserver.model.gameobjects.Creature)
	 */
	@Override
	public boolean isAggroTo(Creature npc)
	{
		if (npc instanceof Player)
		{
			TribeClass baseTribe = DataManager.TRIBE_RELATIONS_DATA.getBaseTribe(this.getTribe());
			if (baseTribe != null)
			{
				switch(baseTribe)
				{
					case GUARD:
						if (npc.getObjectTemplate().getRace() == Race.ELYOS)
							return false;
					case GUARD_DARK:
						if (npc.getObjectTemplate().getRace() == Race.ASMODIANS)
							return false;
				}
			}
			return true;
		}
		return super.isAggroTo(npc);
	}
	
	/* (non-Javadoc)
	 * @see com.aionemu.gameserver.model.gameobjects.instance.Monster#getRelation(com.aionemu.gameserver.model.gameobjects.player.Player)
	 */
	@Override
	public Relations getRelation(Player player)
	{
		if (super.isAggroTo(player))
			return Relations.AGRESSIV;
		TribeClass baseTribe = DataManager.TRIBE_RELATIONS_DATA.getBaseTribe(this.getTribe());
		if (baseTribe != null)
		{
			switch(baseTribe)
			{
				case GUARD:
					if (player.getObjectTemplate().getRace() == Race.ELYOS)
						return Relations.NOT_ATTACKABLE;
				case GUARD_DARK:
					if (player.getObjectTemplate().getRace() == Race.ASMODIANS)
						return Relations.NOT_ATTACKABLE;
			}
			
		}
		return Relations.AGRESSIV;
	}

	/* (non-Javadoc)
	 * @see com.aionemu.gameserver.model.gameobjects.Creature#isEnemy(com.aionemu.gameserver.model.gameobjects.Creature)
	 */
	@Override
	public boolean isEnemy(Creature creature)
	{
		if (creature instanceof Player)
		{
			TribeClass baseTribe = DataManager.TRIBE_RELATIONS_DATA.getBaseTribe(this.getTribe());
			if (baseTribe != null)
			{
				switch(baseTribe)
				{
					case GUARD:
						if (creature.getObjectTemplate().getRace() == Race.ELYOS)
							return false;
					case GUARD_DARK:
						if (creature.getObjectTemplate().getRace() == Race.ASMODIANS)
							return false;
				}
			}
		}
		return super.isEnemy(creature);
	}
	/* (non-Javadoc)
	 * @see com.aionemu.gameserver.model.gameobjects.Creature#initializeAi()
	 */
	@Override
	public void initializeAi()
	{
		if (ai != null)
		{
			ai.stopAI();
			ai.setTarget(null);
		}

		ai = AIClasss.getInstance().getAIByName("GuardAI", this);
	}
}
